import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    userInfo: null,
    token: null,
    isLoggedIn: false
  }),

  getters: {
    getUserInfo: state => state.userInfo,
    getToken: state => state.token,
    isAuthenticated: state => state.isLoggedIn
  },

  actions: {
    setUserInfo(userInfo) {
      this.userInfo = userInfo
      this.isLoggedIn = !!userInfo
    },

    setToken(token) {
      this.token = token
    },

    logout() {
      this.userInfo = null
      this.token = null
      this.isLoggedIn = false
    }
  }
})
